package com.carrental.dao;

import java.sql.ResultSet;

import com.carrental.entity.AdminUser;
import com.carrental.util.DBConnection;

public class AdminUserDao {
	
	DBConnection dbConnection;
	
	//根据用户名和密码查询管理员
	public AdminUser selectByNamePwd(String name, String pwd) throws Exception {
		dbConnection = new DBConnection();
		String sql = "select * from admin_user where username=? and password=?";
		
		ResultSet executeQuery = dbConnection.executeQuery(sql, new String[] {name, pwd});
		AdminUser adminUser = null;
		while (executeQuery.next()) {
			adminUser = new AdminUser();
			adminUser.setId(executeQuery.getString("id"));
			adminUser.setUsername(executeQuery.getString("username"));
			adminUser.setPassword(executeQuery.getString("password"));
			adminUser.setCreateDatetime(executeQuery.getTimestamp("create_datetime"));
		}
		dbConnection.closeAll();
		return adminUser;
	}

}
